<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.sp.model.ConnDB"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 管理列表</strong></div>
  <div class="padding border-bottom">
    <button type="button" class="button border-yellow" onclick="window.location.href='#add'"><span class="icon-plus-square-o"></span> 添加用户</button>
  </div>
  <table class="table table-hover text-center">
    <tr>
      <th width="5%">ID</th>
      <th width="15%">用户名</th>
      <th width="10%">密码</th>
      <th width="10%">角色</th>
      <th width="10%">添加时间</th>
      <th width="10%">操作</th>
    </tr>
    <%ConnDB connDB = new ConnDB();
      Connection connection = connDB.getConn();
      Statement statement;
	  String sqlSentence="select * from userinfo";
	  statement = connection.createStatement();
      ResultSet rs = statement.executeQuery(sqlSentence);
      while(rs.next()){           
      %>    
    <tr>
      <td><%=rs.getInt(1)%></td>
      <td><%=rs.getString(2)%></td>
      <td><%=rs.getString(3) %></td>
       <td><%=(rs.getString(4).equals("1")==true?"超级管理员":"普通管理员")%></td>
      <td><%=rs.getDate(5) %></td>
      <td><div class="button-group"> 
      <a class="button border-main" href="javascript:updateUser('<%=rs.getInt(1)%>','<%=rs.getString(2)%>','<%=rs.getString(3)%>','<%=rs.getString(4)%>','<%=rs.getDate(5) %>');" >
      <span class="icon-edit"></span> 修改</a> 
      <a class="button border-red"  
      			onclick="del('<%=rs.getInt(1)%>')" >
      <span class="icon-trash-o"></span> 删除</a> </div></td>
    </tr>
    <!-- <%="return del("+rs.getInt(1)+")"%> -->
   <%} %>
  </table>
</div>
<script type="text/javascript">
function del(id){
	if(confirm("您确定要删除吗?")==true)
	{		
		//alert(id);
		//window.location.href("index.html");
		window.location.href="DeleteUserServlet?id="+id+"";
	}
}
</script>
<div class="panel admin-panel margin-top">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>添加管理员</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="AddUserServlet" onsubmit="return check(this)">
      <div class="form-group">
        <div class="label">
          <label>角色：</label>
        </div>
        <div class="field">
          <select name="pid" class="input w50">
            <option value="">请选择角色</option>
            <option value="2">普通管理员</option>
            <option value="1">超级管理员</option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>登录名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="uname" />
          <div class="tips"></div>
        </div>
      </div>
   
      <div class="form-group">
        <div class="label">
          <label>登录密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" name="upwd" />
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>再次输入密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" name="tupwd"/>
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
</body>

</html>
<script>
function check(form){
if(form.pid.value==""){
alert("请输入管理员类型");
return false;
}
if(form.uname.value==""){
alert("请输入用户名");
return false;}
if(form.upwd.value==""){
alert("请输入密码");return false;}
if(form.tupwd.value==""){
alert("请再次输入密码");return false;}
if(form.upwd.value!=form.tupwd.value){
alert("两次输入的密码不相同");return false;}
return true;
}

function updateUser(userId,username,passwd,role,regtime){
window.location.href="useredit.jsp?id="+userId+"&uname="+
	username+"&upwd="+passwd+"&role="+role;
}
</script>
